<?php
	
function list_divisi(){

//PASANG JAVASCRIPT
my_set_code_js('

function confirmDelete(id){
	var t = confirm(\'Yakin akan menghapus data ?\');
	if(t){
		location.href=\'index.php?com=jenis_peringatan&task=delete&id=\'+id;
	}
	return false;
}

');
	$header = array(
		'Nomor Urut'=>array('style'=>'border-bottom:2px solid;width:15%'), 
		'Jenis Peringatan'=>array('style'=>'border-bottom:2px solid;width:50%'), 
		'Pot. Insentif'=>array('style'=>'text-align:right;border-bottom:2px solid;width:25%'), 
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);

	$query = "SELECT * FROM jenis_peringatan";
	$result = my_query($query);
	$i = 0;
	$row=array();
	while($ey = my_fetch_array($result)){
		$i++;
		$editproperty = array(
						'href'=>'index.php?com=jenis_peringatan&task=editjenis_peringatan&id='.$ey['jenis_peringatan_id'],
						'rel'=>'facebox',
						'title'=>'Edit'
				);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );

		$deleteproperty = array(
						'href'=>'javascript:; ',
						'onclick'=>'javascript:confirmDelete('.$ey['jenis_peringatan_id'].');',
						'title'=>'Delete'
				);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		 
		$row[] = array(
			'no'=>position_text_align ($ey['nomor_urut'], 'center'), 
			'jenis_peringatan'=>  $ey['nama_jenis_peringatan'] ,   
			'pot'=>  position_text_align( $ey['potongan_insentif'].' %', 'right'),     
			'operasi'=> position_text_align(  $edit_button.' '.$delete_button , 'right'),  
		);
		 
	}
	
	$datas = table_rows($row);   
	return table_builder($header , $datas ,  3 , false );
}


function form_jenis_peringatan_validate($id){
	$errsubmit = false;
	$err = array();

	$nama =  trim($_POST["nama_jenis_peringatan"]); 
	if( $nama == ''){
		$errsubmit = true;
		$err[] = "Jenis Peringatan belum diisi";
	}

	$query="SELECT jenis_peringatan_id FROM jenis_peringatan 
		WHERE nama_jenis_peringatan='".$nama.
		"' AND jenis_peringatan_id<>".$id; 
	if (my_num_rows( my_query($query)) >0){
		$errsubmit = true;
		$err[] = "Jenis Peringatan sudah ada";	
	}

	if( $errsubmit){
		return $err;
	}
	
	return $errsubmit;
}

function form_jenis_peringatan_submit($id){
	$datas = array(
		'nomor_urut'=>my_type_data_int( $_POST['nomor_urut'] ),
		'nama_jenis_peringatan'=>my_type_data_str( $_POST['nama_jenis_peringatan'] ),
		'potongan_insentif'=>my_type_data_int( $_POST['potongan_insentif'] ),
		'datetime_added'=>my_type_data_function('NOW()'),
	);
	if($id > 0){
		return my_update_record('jenis_peringatan' ,'jenis_peringatan_id' , $id , $datas);
	}
	
	return my_insert_record('jenis_peringatan' , $datas);
}

function form_jenis_peringatan_create($id = 0){
	$view = form_header( "jenis_peringatan" , "jenis_peringatan"  );
 	$fields = my_get_data_by_id('jenis_peringatan','jenis_peringatan_id',$id);
	$temp = array(
		'name'=>'nomor_urut',
		'value'=>( isset($_POST['nomor_urut']) ? $_POST['nomor_urut'] : $fields['nomor_urut'] ),
		'id'=>'nomor_urut',
		'type'=>'text',
		'size'=>'5'
	);
	$form_temp = form_dynamic($temp);	
	$view .= form_field_display( $form_temp   , "Nomor Urut"   );
	
	$temp = array(
		'name'=>'nama_jenis_peringatan',
		'value'=>( isset($_POST['nama_jenis_peringatan']) ? $_POST['nama_jenis_peringatan'] : $fields['nama_jenis_peringatan'] ),
		'id'=>'nama_jenis_peringatan',
		'type'=>'text',
		'size'=>'45'
	);
	$form_temp = form_dynamic($temp);	
	$view .= form_field_display( $form_temp   , "Jenis Peringatan"   );

	$temp = array(
		'name'=>'potongan_insentif',
		'value'=>( isset($_POST['potongan_insentif']) ? $_POST['potongan_insentif'] : $fields['potongan_insentif'] ),
		'id'=>'potongan_insentif',
		'type'=>'text',
		'size'=>'3'
	);
	$form_temp = form_dynamic($temp);	
	$view .= form_field_display( $form_temp." %"   , "Potongan Insentif"   );
		
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	$view .= form_field_display( $form_submit  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}
function remove_jenis_peringatan($id){
	$query= "DELETE FROM jenis_peringatan WHERE jenis_peringatan_id = {$id}";
	return my_query($query);
} 
 